package com.kevin.j2eeToolBox.awt;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.UnsupportedEncodingException;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class AwtCalc {

	public static void main(String[] args) throws UnsupportedEncodingException {

		CalcFrame frame = new CalcFrame();
	}

}

class CalcFrame extends JFrame {

	private Container contentPane = this.getContentPane();

	private JTextField textField;
	private JButton mcButton = new JButton("MC");
	private JButton mrButton = new JButton("MR");
	private JButton msButton = new JButton("MS");
	private JButton maddButton = new JButton("M+");
	private JButton mdButton = new JButton("M-");

	private JPanel jp = new JPanel();
	private JPanel jp1 = new JPanel();
	private JPanel jp2 = new JPanel();
	private JPanel jp3 = new JPanel();

	private Box horibox1 = Box.createHorizontalBox();
	private Box horibox2 = Box.createHorizontalBox();
	private Box horibox3 = Box.createHorizontalBox();
	private Box verbox = Box.createVerticalBox();

	public CalcFrame() {
		super();

		this.setTitle("计算器");
		this.setSize(228, 320);
		this.setResizable(false);
		this.getContentPane().setLayout(new BorderLayout());
		this.setVisible(true);
		this.addWindowListener(new CalcWindowsListener());

		InitMenu();

		textField = new JTextField("0.", 17);
		textField.setEditable(false);
		textField.setSize(200, 100);
		textField.setHorizontalAlignment(JTextField.RIGHT);

		jp.add(textField);
		contentPane.add(jp, BorderLayout.NORTH);

		//

		//
		// mcButton.setSize(40, 30);
		// this.getContentPane().add(mcButton);
		//
		// mrButton.setSize(40, 30);
		// this.getContentPane().add(mrButton);
		//
		// msButton.setSize(40, 30);
		// this.getContentPane().add(msButton);
		//
		// maddButton.setSize(40, 30);
		// this.getContentPane().add(maddButton);
		//
		// mdButton.setSize(40, 30);
		// this.getContentPane().add(mdButton);

		// this.pack();

	}

	private void InitMenu() {

		JMenuBar mnb = new JMenuBar();

		JMenu viewMenu = new JMenu("查看(V)");
		JMenu editMenu = new JMenu("编辑(E)");
		JMenu helpMenu = new JMenu("帮助(H)");

		JMenuItem item1 = new JMenuItem("标准型");
		viewMenu.add(item1);

		mnb.add(viewMenu);
		mnb.add(editMenu);
		mnb.add(helpMenu);
		this.setJMenuBar(mnb);
	}
}

class CalcWindowsListener extends WindowAdapter {

	@Override
	public void windowClosing(WindowEvent e) {

		System.out.println("退出");
		System.exit(0);
	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
		super.windowClosed(e);
	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		super.windowIconified(e);
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
		super.windowDeiconified(e);
	}

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		super.windowActivated(e);
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		super.windowDeactivated(e);
	}

	@Override
	public void windowStateChanged(WindowEvent e) {
		// TODO Auto-generated method stub
		super.windowStateChanged(e);
	}

	@Override
	public void windowGainedFocus(WindowEvent e) {
		// TODO Auto-generated method stub
		super.windowGainedFocus(e);
	}

	@Override
	public void windowLostFocus(WindowEvent e) {
		// TODO Auto-generated method stub
		super.windowLostFocus(e);
	}

}
